<template>
	<div class="port-page">

		<div class="but1">
			<!--<router-link to="/home">
			<el-button type="warning" size="small"  class="add btn" style='margin-right: 10px;' icon="el-icon-menu">首页</el-button>
		</router-link>-->
		</div>
		<el-tabs v-model="activeName" type="card" @tab-click='tabchk'>
			<el-tab-pane label="教材合并" name="jchb"></el-tab-pane>
			<el-tab-pane label="教材拆分" name="jccf"></el-tab-pane>
			<el-tab-pane label="日志" name="rz"></el-tab-pane>
		</el-tabs>
		<div style="overflow: hidden;">
			<router-link to="/home" style="width: 19%; float: left; height: 50px; line-height: 50px;">
				<el-button type="warning" size="small" class="add btn" style='margin-right: 5px;' icon="el-icon-menu">首页</el-button>
			</router-link>
			<div style="width: 80%; text-align: right; float: right;line-height: 50px;" v-if="showhb">
				<el-input placeholder="请输入物品名称" class="code-search" v-model="vkeyword" icon="search"></el-input>
				<el-select v-model="vwpflid" class="code-search" @change="search()" placeholder="请选择分类">
					<el-option :label="v.mc" :value="v.id" v-for="v in comboxlist"></el-option>
				</el-select>
				<el-button type="primary" size="small" class="add btn" round style="border-radius:13px;" :loading="searchLoading" @click="search()" icon="el-icon-search"></el-button>

				<!--<el-button icon="el-icon-search" type="primary" round size="small" @click="search()"></el-button>-->
			</div>
			<div style="width: 80%; text-align: right; float: right; line-height: 50px;" v-if="showcf">
				<el-input placeholder="请输入物品名称" class="code-search" v-model="vkeyword" icon="search"></el-input>
				<el-select v-model="vwpflid" class="code-search" @change="search2()" placeholder="请选择分类">
					<el-option :label="v.mc" :value="v.id" v-for="v in comboxlist"></el-option>
				</el-select>
				<el-button type="primary" size="small" class="add btn" round style="border-radius:13px;" :loading="searchLoading" @click="search2()" icon="el-icon-search"></el-button>
				<!--<el-button icon="el-icon-search" type="primary" round size="small" @click="search2()"></el-button>-->
			</div>
			<div style="width: 80%; text-align: right; float: right;line-height: 50px;" v-if="showrz">
				<el-input placeholder="请输入物品名称" class="code-search" v-model="vkeyword" icon="search"></el-input>
				<!--<el-select v-model="vwpflid" class="code-search" @change="search3()" placeholder="请选择物品分类">
				<el-option :label="v.mc" :value="v.id" v-for="v in comboxlist"></el-option>
			</el-select>-->
				<el-date-picker v-model="btime" type="date" class="code-search" :editable="false" value-format="yyyy-MM-dd" placeholder="选择日期">
				</el-date-picker>
				<el-date-picker v-model="etime" type="date" class="code-search" :editable="false" value-format="yyyy-MM-dd" placeholder="选择日期">
				</el-date-picker>
				<el-button type="primary" size="small" class="add btn" round style="border-radius:13px;" :loading="searchLoading" @click="search3()" icon="el-icon-search"></el-button>

				<!--<el-button icon="el-icon-search" type="primary" round size="small" @click="search3()"></el-button>-->
			</div>
		</div>

		<el-table v-if="showhb" :data="dataList1" border stripe size="small" align="left" class="admin-table" @select="checkSelect" @select-all="checkall">
			<!--<el-table-column type="selection" width="55"></el-table-column>-->
			<div slot='empty'>
				<img src="../../../assets/img/empty.png" style="width:40px;vertical-align: middle;">
				<span style="vertical-align: middle;">暂时还没有内容哦!</span>
			</div>
			<el-table-column type="expand" label="配件" width="60">
				<template slot-scope="props">
					<el-table :data="props.row.sonlist"  border stripe align="left" size="mini " class="admin-table" @select="checkSelect" @select-all="checkall">
						<div slot='empty'>
							<img src="../../../assets/img/empty.png" style="width:40px;vertical-align: middle;">
							<span style="vertical-align: middle;">暂时还没有添加配件哦!</span>
						</div>
						<el-table-column :prop="v.prop" :label="v.label" v-for="(v,index) in portTitleList4" align="center" show-overflow-tooltip v-if="v.hide != 0" :formatter="v.formatter" :align="v.align || 'center'" :fixed="v.fixed" :class-name="v.columnStyle" :width="v.width" :min-width="v.minWidth" :header-align="v.headerAlign || 'center'">
							<template scope="scope">
								<div slot="reference" :style="tableCellControl(scope)">
									{{ scope.row[scope.column.property] }}
								</div>
							</template>
						</el-table-column>
					</el-table>
				</template>
			</el-table-column>
			<el-table-column :prop="v.prop" :label="v.label" v-for="(v,index) in portTitleList1" align="center" show-overflow-tooltip v-if="v.hide != 0" :formatter="v.formatter" :align="v.align || 'center'" :fixed="v.fixed" :class-name="v.columnStyle" :width="v.width" :min-width="v.minWidth" :header-align="v.headerAlign || 'center'">
				<template scope="scope">
					<div slot="reference" :style="tableCellControl(scope)">
						{{ scope.row[scope.column.property] }}
					</div>
				</template>
			</el-table-column>
			<!-- <el-table-column label="操作" width="160" align="center"> -->
			<el-table-column fixed="right" align="center" label="操作" width="180px">
				<template scope="scope">
					<!-- v-if="scope.row.qx == 'Y'"-->
					<el-button size="mini" type="primary" @click="componentsShow('add',scope)">合并</el-button>
					<!--<el-button size="mini" type="success" @click="componentsShow('info',scope)">配件详情</el-button>-->
				</template>
			</el-table-column>
		</el-table>

		<el-table v-if="showcf" :data="dataList2" border stripe size="small" align="left" class="admin-table" @select="checkSelect" @select-all="checkall">
			<!--<el-table-column type="selection" width="55"></el-table-column>-->
			<div slot='empty'>
				<img src="../../../assets/img/empty.png" style="width:40px;vertical-align: middle;">
				<span style="vertical-align: middle;">暂时还没有内容哦!</span>
			</div>
			<el-table-column type="expand" label="配件" width="60">
				<template slot-scope="props">
					<el-table :data="props.row.sonlist" border stripe align="left" size="mini " class="admin-table" @select="checkSelect" @select-all="checkall">
						<div slot='empty'>
							<img src="../../../assets/img/empty.png" style="width:40px;vertical-align: middle;">
							<span style="vertical-align: middle;">暂时还没有添加配件哦!</span>
						</div>
						<el-table-column :prop="v.prop" :label="v.label" v-for="(v,index) in portTitleList4" align="center" show-overflow-tooltip v-if="v.hide != 0" :formatter="v.formatter" :align="v.align || 'center'" :fixed="v.fixed" :class-name="v.columnStyle" :width="v.width" :min-width="v.minWidth" :header-align="v.headerAlign || 'center'">
							<template scope="scope">
								<div slot="reference" :style="tableCellControl(scope)">
									{{ scope.row[scope.column.property] }}
								</div>
							</template>
						</el-table-column>
					</el-table>
				</template>
			</el-table-column>
			<el-table-column :prop="v.prop" :label="v.label" v-for="(v,index) in portTitleList2" align="center" show-overflow-tooltip v-if="v.hide != 0" :formatter="v.formatter" :align="v.align || 'center'" :fixed="v.fixed" :class-name="v.columnStyle" :width="v.width" :min-width="v.minWidth" :header-align="v.headerAlign || 'center'">
				<template scope="scope">
					<div slot="reference" :style="tableCellControl(scope)">
						{{ scope.row[scope.column.property] }}
					</div>
				</template>
			</el-table-column>
			<!-- <el-table-column label="操作" width="160" align="center"> -->
			<el-table-column fixed="right" align="center" label="操作" width="180px">
				<template scope="scope">
					<!-- v-if="scope.row.qx == 'Y'"-->
					<el-button size="mini" type="primary" @click="componentsShow('add',scope)">拆分</el-button>
					<!--<el-button size="mini" type="success" @click="componentsShow('info',scope)">配件详情</el-button>-->
				</template>
			</el-table-column>
		</el-table>
		<el-table v-if="showrz" :data="dataList3" border stripe size="small" align="left" class="admin-table" @select="checkSelect" @select-all="checkall">
			<!--<el-table-column type="selection" width="55"></el-table-column>-->
			<div slot='empty'>
				<img src="../../../assets/img/empty.png" style="width:40px;vertical-align: middle;">
				<span style="vertical-align: middle;">暂时还没有内容哦!</span>
			</div>
			<el-table-column :prop="v.prop" :label="v.label" v-for="(v,index) in portTitleList3" align="center" show-overflow-tooltip v-if="v.hide != 0" :formatter="v.formatter" :align="v.align || 'center'" :fixed="v.fixed" :class-name="v.columnStyle" :width="v.width" :min-width="v.minWidth" :header-align="v.headerAlign || 'center'">
				<template scope="scope">
					<div slot="reference" :style="tableCellControl(scope)">
						{{ scope.row[scope.column.property] }}
					</div>
				</template>
			</el-table-column>

		</el-table>

		<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page.sync="pageindex" :page-sizes="pagesizes" :page-size="pagesize" :layout="layout" :total="total" class="class-page"></el-pagination>

		<!-- 各个组件显示区域 -->
		<!-- 动画加载 -->
		<infoComponent v-if="portComponents.info.toggle" @close="componentsHide" :params="portComponents.info.params"></infoComponent>
		<AddComponent v-if="portComponents.add.toggle" @close="componentsHide" :params="portComponents.add.params"></AddComponent>
		<LoadingComponent v-show="isLoading"></LoadingComponent>

		<!-- 子路由显示区域 -->
		<router-view class="port-view"> </router-view>
	</div>
</template>
<script>
	import { mapState } from 'vuex'
	import LoadingComponent from 'components/loading'
	import AddComponent from './add'
	import InfoComponent from './info'

	import qs from 'qs'
	export default {
		props: ['params'],
		components: {
			LoadingComponent,
			AddComponent,
			InfoComponent
		},
		data() {
			return {
				btime: '',
				etime: '',
				activeName: 'jchb',
				vkeyword: '',
				showhb: true,
				showcf: false,
				showrz: false,
				/*模糊搜索条件*/
				vwpflid: '',
				multipleDelNum: '', //获取批量选择的数据
				dataList1: [], //表格数据
				dataList2: [], //表格数据
				dataList3: [], //表格数据
				comboxlist: [], //下拉框 动态的

				/*动画加载*/
				isLoading: true, //动画加载
				searchLoading: false, //搜索按钮触发按钮动画
				/*分页属性设置*/
				layout: 'total, sizes, prev, pager, next, jumper', //组件布局
				pageindex: this.$store.state.pageindex, //当前分页页码
				pagesizes: this.$store.state.pagesizes, //显示个数的选择器选项
				pagesize: this.$store.state.pagesize, //每页显示条目数
				total: 0, //总条数

				/*组件区域*/
				portComponents: {

					//采购入库
					add: {
						type: 'add',
						toggle: false,
						params: '',
						data: {}
					},

					/* info */
					info: {
						type: 'info',
						toggle: false,
						params: '',
						data: {}
					}
				},
				/*
				    prop :  接口参数名
				    label : 接口中文名
				    hide : 是否隐藏这一列
				    align : 这一列对齐顺序 ： left,right,center
				    headerAlign : 这一列表头对齐方式 ： left,right,center
				*/
				portTitleList1: [{
						prop: 'flmc',
						label: '物品分类',
						hide: 1,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},
					{
						prop: 'wpmc',
						label: '物品名称',
						hide: 1,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},
					{
						prop: 'cnt',
						label: '合并数量',
						hide: 0,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},
					{
						prop: 'jg1',
						label: '价格/单位',
						hide: 1,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},
					{
						prop: 'cnt1',
						label: '最大合并数量',
						hide: 1,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},
					{
						prop: 'dw',
						label: '单位',
						hide: 0,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},
					{
						prop: 'pjxx',
						label: '配件信息',
						hide: 0,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},
				],
				portTitleList2: [{
						prop: 'flmc',
						label: '物品分类',
						hide: 1,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},
					{
						prop: 'wpmc',
						label: '物品名称',
						hide: 1,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},
					{
						prop: 'cnt',
						label: '拆分数量',
						hide: 0,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},
					{
						prop: 'jg1',
						label: '价格/单位',
						hide: 1,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},
					{
						prop: 'cnt',
						label: '库存数量',
						hide: 1,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},
					{
						prop: 'dw',
						label: '单位',
						hide: 0,
						align: 'center',
						fixed: false,
						width: '80',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},
					{
						prop: 'pjmc',
						label: '配件名称',
						hide: 0,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},
				],
				portTitleList3: [{
						prop: 'cflx',
						label: '操作类型',
						hide: 1,
						align: 'center',
						fixed: false,
						width: '80',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},
					{
						prop: 'wpmc',
						label: '物品名称',
						hide: 1,
						align: 'center',
						fixed: false,
						width: '100',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},
					{
						prop: 'wpsl',
						label: '物品数量',
						hide: 1,
						align: 'center',
						fixed: false,
						width: '100',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},
					{
						prop: 'jg1',
						label: '价格/单位',
						hide: 1,
						align: 'center',
						fixed: false,
						width: '100',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},
					{
						prop: 'sj',
						label: '时间',
						hide: 1,
						align: 'center',
						fixed: false,
						width: '120',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},
					{
						prop: 'pjmc',
						label: '配件名称',
						hide: 1,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},

					{
						prop: 'dw',
						label: '单位',
						hide: 0,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},
					{
						prop: 'note',
						label: '备注',
						hide: 1,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},
				],
				portTitleList4: [{
						prop: 'mc',
						label: '配件名称',
						hide: 1,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},
					{
						prop: 'dw',
						label: '单价',
						hide: 1,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},
					{
						prop: 'cnt',
						label: '当前库存数量',
						hide: 1,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},
					
					{
						prop: 'sj',
						label: '可以合并数',
						hide: 0,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},
				
				]
			}
		},
		created() {
			//加载页面时调用
			this.$store.dispatch('changeTitle', '教材拆分合并'); //修改title
			this.$store.dispatch('changeRouterIndex', '/manage/cfhb'); //修改路由
			this.getcomboxlist(); //加载下拉列表
			this.search(); //分页获取默认数据
			this.isLoading = true; //动画开始
		},
		mounted() {
			//加载完成之后event
			this.isLoading = false; //动画结束
		},
		methods: {
			tabchk(tab) {
				if(tab.name == 'jchb') {
					this.showhb = true;
					this.showcf = false;
					this.showrz = false;
					this.search()
				} else if(tab.name == 'jccf') {
					this.showhb = false;
					this.showcf = true;
					this.showrz = false;
					this.search2()
				}
				if(tab.name == 'rz') {
					this.showhb = false;
					this.showcf = false;
					this.showrz = true;
					this.search3()
				}
			},
			getcomboxlist() {
				var logininfo = JSON.parse(localStorage.logininfo);
				var params3 = qs.stringify({
					ms: '12',
					yhid: logininfo.id,
					xxid: logininfo.xxid,
				});
				this.searchLoading = true;
				this.axios.post(this.$store.state.api + 'wpfl/getlist1', params3)
					.then(res => {
						//						console.log(res, 9898)
						let data = res.data.data;
						let list = data.list;
						this.comboxlist = list;
					}).catch(res => {
						this.searchLoading = false;
					})
			},

			search() {
				//查询搜索触发事件
				var logininfo = JSON.parse(localStorage.logininfo);
				var params3 = qs.stringify({
					wpfl: this.vwpflid + '',
					wpmc: this.vkeyword, // 关键字
					yhid: logininfo.id,
					xxid: logininfo.xxid,
					pageindex: this.pageindex,
					pagesize: this.pagesize
				});
				this.axios.post(this.$store.state.api + 'wpfx/web_getwpcfhbhblist', params3)
					.then(res => {
						console.log(res, 9898888888)
						let data = res.data.data;
						let list = data.list;
						this.total = data.totalPage;
						this.dataList1 = list;
						this.searchLoading = false;
					}).catch(res => {
						this.searchLoading = false;
					})
			},
			search2() {
				//查询搜索触发事件
				var logininfo = JSON.parse(localStorage.logininfo);
				var params3 = qs.stringify({
					wpflid: this.vwpflid + '',
					wpmc: this.vkeyword, // 关键字
					yhid: logininfo.id,
					xxid: logininfo.xxid,
					pageindex: this.pageindex,
					pagesize: this.pagesize
				});
				this.axios.post(this.$store.state.api + 'wpfx/web_getwpcfhblist', params3)
					.then(res => {
						console.log(res, 222)
						let data = res.data.data;
						let list = data.list;
						this.total = data.totalPage;
						this.dataList2 = list;
						this.searchLoading = false;
					}).catch(res => {
						this.searchLoading = false;
					})
			},
			search3() {
				//查询搜索触发事件
				var logininfo = JSON.parse(localStorage.logininfo);
				var params3 = qs.stringify({
					wpflid: this.vwpflid + '',
					wpmc: this.vkeyword, // 关键字
					btime: this.btime,
					etime: this.etime,
					yhid: logininfo.id,
					xxid: logininfo.xxid,
					pageindex: this.pageindex,
					pagesize: this.pagesize
				});
				this.axios.post(this.$store.state.api + 'wpfx/web_getwpcfhbrzlist', params3)
					.then(res => {
						console.log(res, 9898888888)
						let data = res.data.data;
						let list = data.list;
						this.total = data.totalPage;
						this.dataList3 = list;
						this.searchLoading = false;
					}).catch(res => {
						this.searchLoading = false;
					})
			},
			tableCellControl(scope) {
				//表格单元格控制CSS样式
				/*if (scope.row.id == 112 && scope.column.property == "iname") {
				    return {
				        color:"red",
				    }
				}else{
				    return {
				        color:"green",
				    }
				}*/
			},
			handleSizeChange(val) { //每页显示条数触发事件
				this.pagesize = val;
				this.pageindex = 1;
				if(this.showhb) {
					this.search();
				}
				if(this.showcf) {
					this.search2();
				}
				if(this.showrz) {
					this.search3();
				}
			},
			handleCurrentChange(val) { //分页触发事件
				if(this.showhb) {
					this.search();
				}
				if(this.showcf) {
					this.search2();
				}
				if(this.showrz) {
					this.search3();
				}
			},
			checkSelect(selection, row) { //点击单选select触发事件
				console.log(selection, row)
				let strID = [];
				selection.forEach(function(v, i) {
					strID.push(v.id)
				})
				this.multipleDelNum = strID.join(",");
			},
			checkall(selection) { //点击全选select触发事件
				let strID = [];
				selection.forEach(function(v, i) {
					strID.push(v.id)
				})
				this.multipleDelNum = strID.join(",");
			},
			/* 组件的弹框  */
			componentsShow(type, data) { //显示组件 
				console.log(data)
				for(let i in this.portComponents) {
					if(type == this.portComponents[i].type) {
						this.portComponents[i].toggle = true;
						this.portComponents[i].params = data;
						return;
					}
				}
			},
			componentsHide(setting) { //关闭组件
				console.log(setting)
				for(let i in this.portComponents) {
					if(setting.type == this.portComponents[i].type) {
						this.portComponents[i].toggle = false;
						if(!setting.cancel) {
							this.search();
						}
						return;
					}
				}
			}
		},
		computed: {
			...mapState([
				'api' //域名
			]),
			multipleDeleteDisabled() {
				console.log(this.multipleDelNum)
				if(this.multipleDelNum) {
					return false;
				} else {
					return true
				}
			}
		}
	}
</script>

<style lang="less" scoped>
	.port-page {
		font-size: 12px;
		.btn {
			height: 30px;
			padding: 0 10px;
		}
		.code-search {
			max-width: 130px;
			min-width: 100px;
			text-align: center;
			height: 50px;
			/*line-height: 50px;*/
			font-size: 12px;
		}
		.code-search1 {
			height: 30px;
			margin: 10px 0 10px 0;
			min-width: 60px;
			max-width: 75px;
		}
		.class-page {
			text-align: left;
			margin-top: 10px;
		}
		.search-item {
			display: inline-block;
			/*margin-right:10px;*/
		}
		.but1 {
			width: 100%;
			margin-top: 8px;
			margin-bottom: 8px;
		}
		.search {
			width: 70%;
			float: right;
			line-height: 50px;
			text-align: right;
		}
		.el-button+.el-button {
			margin-left: 5px;
		}
	}
</style>